<!doctype html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common::heads(~{::title},~{},~{},~{})">
    <title>登录</title>
</head>
<body class="bg-body-tertiary">

<div class="d-flex align-items-center justify-content-center">
  <div class="p-2" style="width: 400px;max-width: 100%;margin-top: 12vh;">
    <h2 class="text-center">bootstrap-admin</h2>
    <p class="text-secondary text-center">基于bootstrap5.1.3设计的后台管理模板系统</p>
    <form class="form" id="form">
      <div class="mb-3">
        <div class="input-group">
          <span class="input-group-text bg-white "><i class="bi bi-person"></i></span>
          <input aria-label="username" class="form-control" id="username" name="username" placeholder="请输入用户" type="text">
        </div>
      </div>

      <div class="mb-3">
        <div class="input-group bsa-show_hide_password">
          <span class="input-group-text bg-white"><i class="bi bi-person-lock"></i></span>
          <input aria-label="password" autocomplete="off" class="form-control" id="password" name="password" placeholder="请输入密码" type="password">
          <span class="input-group-text bg-white bsa-cursor-pointer"><i class="bi bi-eye-slash"></i></span>
        </div>
      </div>

      <!--<div class="mb-3">
        <div class="input-group">
          <span class="input-group-text bg-white"><i class="bi bi-shield-lock"></i></span>
          <input aria-label="captcha" class="form-control" id="captcha" name="captcha" placeholder="请输入验证码" style="min-width: 80px" type="text">
          <img alt="验证码" class="bsa-cursor-pointer" src="/dist/img/captcha.gif" style="height: 38px;width: 120px"/>
        </div>
      </div>-->

      <!--<div class="mb-3 d-flex align-items-center justify-content-between flex-wrap gap-3 ">
        <div class="form-check">
          <input class="form-check-input" id="exampleCheck1" name="remember" type="checkbox" value="1">
          <label class="form-check-label" for="exampleCheck1">十天内免登录</label>
        </div>
        <a class="link-success text-decoration-none" href="javascript:">忘记密码?</a>
      </div>-->

      <div class="mb-3 alert alert-danger d-flex align-items-center justify-content-center d-none" id="msg" role="alert"></div>

      <div class="d-grid gap-2">
        <button class="btn btn-outline-success" type="submit"><i class="bi bi-box-arrow-in-right"></i> 登入</button>
      </div>

    </form>
  </div>
</div>
<th:block th:replace="common::scripts(~{})"></th:block>
<script>
    $(function () {
        $('#form').formValidation({
            fields: {
                username: {
                    validators: {
                      notEmpty: {message:'账户不能为空'},
                      stringLength:{min:2,max:10,message: '账户长度在2到10个字符之间'}
                    }
                },
                password: {
                    validators: {
                      notEmpty: {message:'密码不能为空'},
                      stringLength:{min:2,max:10,message: '密码长度在2到10个字符之间'}
                    }
                }
            }
        }).on('success.form.fv', function (e) {
            e.preventDefault();
            let $form = $(e.target);
            let data = $form.serialize();
            $.ajax({url:'/common/login',data:data,method:'post'}).then(response => {
                if (response.flag) {
                  $('#msg').addClass('d-none');
                  top.location.replace('/admin');
                }else{
                  $('#msg').text(response.msg);
                  $('#msg').removeClass('d-none');
                }
            });
        });
    })
</script>
</body>
</html>
